# -*- coding:utf-8 -*-
import sys, shutil
import os
import django

sys.path.append(".")
os.environ.update({"DJANGO_SETTINGS_MODULE": "server.settings"})
try:
    django.setup()
except:
    print("ERROR: django init Error")

from django.conf import settings

sysConfig = settings.CONFIG


def copy(oldPath, newPathDir):
    shutil.copy(oldPath, newPathDir)


if __name__ == '__main__':
    try:
        clearFiles = []
        clearFiles.append(sysConfig["dataDir"])
        for filePath in clearFiles:
            if (os.path.exists(filePath)):
                # os.remove(filePath)
                shutil.rmtree(filePath)
        print("Init finish !!!!!!")
    except Exception as e:
        print("EORROR: init error")
    try:
        copy(sysConfig["dataBack"], sysConfig["dataDir"])
    except Exception as e:
        print("ERROR: data dir can not be created")
